﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Text;
using Sherwood.Security;
using Sherwood.SignOn.Server.Models;
using Sherwood.SignOn.Server.Models.Repositories;
using Sherwood.SignOn;
using Sherwood.SignOn.Server;
using Sherwood.SignOn.Server.Models.Services;

namespace Sherwood.SignOn.Server.Models.Repositories.InMemory
{
    [Serializable]
    public class UserSession : IUserSession
    {
        static UserSession()
        {

        }

        /// <summary>
        /// Primary key for user account.
        /// </summary>
        public virtual Guid Id { get; set; }

        public virtual IUserAccount UserAccount
        {
            get
            {
                return InMemoryRepository.UserAccounts.GetUserAccount(UserAccountId);
            }
            set
            {
                if (value != null)
                {
                    UserAccountId = value.Id;
                    if (!InMemoryRepository.UserSessions.All.Contains(this))
                        InMemoryRepository.UserSessions.All.Add(this);
                }
                else
                {
                    UserAccountId = Guid.Empty;
                }
            }
        }

        public Guid UserAccountId {get; set;}

        public string IpAddress { get; set; }

        public DateTime DateCreated { get; set; }

        public bool? Persistent { get; set; }

        private List<UserSessionClientRecord> _clientRecords = new List<UserSessionClientRecord>();
        IEnumerable<IUserSessionClientRecord> IUserSession.ClientRecords
        {
            get
            {
                return _clientRecords;
            }
        }

        public virtual List<UserSessionClientRecord> ClientRecords
        {
            get
            {
                return _clientRecords;
            }
        }


       

    }
}
